using Microsoft.Extensions.DependencyInjection;
using NLog.Web;
using System.Reflection;
using NLog.Web;
using Traceability.App.Intrastructure.Interface;
using Traceability.App.Intrastructure.Implement;
using Traceability.App.Intrastructure;
using Microsoft.EntityFrameworkCore;
namespace Traceability.App.Api.Read
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();
            builder.Services.AddSwaggerGen(x =>
            {
                var file = AppContext.BaseDirectory + @"Traceability.App.Api.Read.xml";
                x.IncludeXmlComments(file, true);
            });
            builder.Host.UseNLog();
            builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));

            builder.Services.AddDbContext<MyDbContext>(x=>x.UseSqlServer(builder.Configuration.GetConnectionString("db")));
            builder.Services.AddMediatR(x =>
            {
                x.RegisterServicesFromAssemblies(Assembly.GetEntryAssembly());
            });
            builder.Services.AddAutoMapper(typeof(MapperProFile));
            builder.Services.AddCors(x =>
            {
                x.AddPolicy("2211A", policy =>
                {
                    policy.WithOrigins("http://localhost:5090").AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin();
                });
            });
            var app = builder.Build();


            app.UseStaticFiles();

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }
            app.UseCors("2211A");
            app.UseAuthorization();


            app.MapControllers();

            app.Run();
        }
    }
}
